/**
 * Copyright 2015 Qiyi Inc. All rights reserved.
 *
 * @file:   Channel.Action.js
 * @path:   js-src/Channel/
 * @desc:   Action静态对象，声明对象以及绑定事件、对外接口等
 * @author: jiegang@qiyi.com
 * @date:   2015-01-10
 */
qui(
    function(require, exports, module) {


        Channel.Action = (function() {

            // 表格
            var channelGrid = null;
            var channelEditForm = null;



            var getChannelGrid = function(options) {

                if (!channelGrid) {
                    channelGrid = new Channel.Grid($.extend(true, {
                        '$container': $('#ChannelListContainer'),
                        type: 0
                    }, options));
                }

                return channelGrid;

            }

            var channelGridRun = function(options) {

                channelGrid = getChannelGrid(options);
                channelGrid.run();

                console.log('grid run');

            }

            // 频道列表
            var run = function() {

                Ancestor.Config.EPG_AUTH.list = '/channel/list';
                channelGridRun({});

            }

            // 频道新建/编目
            var editRun = function() {
                channelEditRun({});



            }

            var channelEditRun = function(options) {

                channelEditForm = getChannelEdit(options);
                channelEditForm.run();
                console.log('channelEditRun run');

            }

            function getChannelEdit(options){
                if (!channelEditForm) {
                    channelEditForm = new Channel.Edit($.extend(true, {
                        '$container': $('.channel-edit-form'),
                        type: 0
                    }, options));
                }
                return channelEditForm;
            }

            return {
                run: run,
                editRun: editRun,
                getChannelGrid: getChannelGrid
            }
        })();
    }
);